Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
Express returns "not found" intermittently

I've been working with express for years, and I'm a bit rusty on the typescript side - however... I think I have gone blind! Its the first time I encounter this, so I must be doing something wrong...

My problem is this:

  • I have an endpoint called "/status".
  • When I call it, it will sometimes return OK;
  • And other times it will return a 404 Not Found.
  • This is the SAME endpoint doing this intermittently.

Here is my express app's code:

import bodyParer from "body-parser";
import methodOverride from "method-override";
import helmet from "helmet";
import fileUpload from "express-fileupload";
import cors from "cors";
import { errors } from "celebrate";
import { expressRouter } from "./routes";
import config from "../config/config";
import { ErrorHandlers } from "../middleware";

const expressApp = express();

expressApp.use(bodyParer.json());
expressApp.use(methodOverride());
expressApp.use(helmet());
expressApp.use(fileUpload());
expressApp.use(cors());
expressApp.use(errors());

expressApp.use(config.api.v1Prefix, expressRouter);

const errorHandlers = new ErrorHandlers();
expressApp.use(errorHandlers.notFound);
expressApp.use(errorHandlers.handler);

export { expressApp };

This is what the router looks like:

// import user from "../routes/user";

const expressRouter = Router();

expressRouter.get("/status", (req, res) => res.send("OK"));

// user(expressRouter); // TODO: finish this off when above '/status' works...

export { expressRouter };

I also suspect the error handlers we have, and this is what they look like:

import { inversifyContainer } from "../config/inversify_config";
import { TYPES } from "../config/inversify_types";
import { Logger } from "../loaders/logger";
import httpStatus from "http-status";

export class ErrorHandlers {
  loggerDependency = inversifyContainer.get<Logger>(TYPES.LoggerDependency);

  notFound(req, res, next) {
    const error = new Error("Not Found");
    error["status"] = 404;
    next(error);
  }

  public handler(err, req, res, next) {
    const response = {
      code: err.status,
      message: err.message || httpStatus[err.status],
      errors: err.errors,
      stack: err.stack,
    };

    if (process.env.NODE_ENV !== "development") {
      delete response.stack;
    }

    res.status(err.status);
    res.json(response);
  }
}

Has anyone else experienced this before? Please let me know if there is anything else I can provide for assistance.

Up to now I have not been able to identify the issue. Any help will be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So... ehmmm.

We are using cloud foundry (in IBM).

What happened was that, in the past, our continuous deployment got stuck. Then we manually cancelled that deployment, so that the queued-up deployments could run and proceed at the time :)

What I realised today was that the OLD app never got deleted. This was a cloud foundry service that was running on the same domain (url) as the active cloud foundry service, which effectively made it 2 running instances, in other words.

The OLD service obviously did not have this new endpoint and it never would, as it was detached from the deployment.

Once I deleted the old service, this issue completely disappeared.

Thanks for anyone that took the time to read through all this nonense. Cheers!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda